package cn.edu.Day11;

import java.io.*;

//管道输入流
public class PipedInput implements Runnable{
    File srcFile;
    PipedOutputStream pos;
    public PipedInput(File srcFile) {
        this.srcFile = srcFile;
        pos = new PipedOutputStream();
    }

    public PipedOutputStream getOutputStream(){
        return pos;
    }

    public void run() {
        try {
            InputStream is = new FileInputStream(srcFile);
            int len = -1;
            byte bs [] = new byte[1024];
            while((len=is.read(bs))!=-1){
                pos.write(bs,0,len);//将文件获取的内容写出去
            }
            is.close();
            pos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
